
package br.diego.tb.twitter;



public class Typeahead 
{
	private static final String LEXICOGRAPHICALLY_GREAT_NAME = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
	
    public static void typeahead(String[] usernames, String[] queries) 
    {
    	String smallestMatchedUsername = LEXICOGRAPHICALLY_GREAT_NAME;
    	
    	for(String query : queries)
    	{
    		boolean matched = false;
    		smallestMatchedUsername = LEXICOGRAPHICALLY_GREAT_NAME;
    		
    		query = query.toLowerCase();
    		
    		for(String username : usernames)
    		{
    			if (username.toLowerCase().startsWith(query))
    			{
    				matched = true;
    				
					if(username.compareToIgnoreCase(smallestMatchedUsername) < 0)
    						smallestMatchedUsername = username;
    			}
    		}
    		
    		if(!matched)
    			System.out.println(-1);
    		else
    			System.out.println(smallestMatchedUsername);
    	}
    }

}
